/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/idenger">idenger</a> All rights reserved.
 */
package com.idenger.modules.edu.web.course;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.idenger.common.web.BaseController;
import com.idenger.modules.edu.service.course.EduVideoHistoryService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.idenger.common.config.Global;
import com.idenger.common.persistence.Page;
import com.idenger.common.utils.StringUtils;
import com.idenger.modules.edu.entity.course.EduVideoHistory;

/**
 * 视频历史Controller
 * @author 视频历史
 * @version 2017-12-13
 */
@Controller
@RequestMapping(value = "${adminPath}/edu/course/eduVideoHistory")
public class EduVideoHistoryController extends BaseController {

	@Autowired
	private EduVideoHistoryService eduVideoHistoryService;
	
	@ModelAttribute
	public EduVideoHistory get(@RequestParam(required=false) String id) {
		EduVideoHistory entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = eduVideoHistoryService.get(id);
		}
		if (entity == null){
			entity = new EduVideoHistory();
		}
		return entity;
	}
	
	@RequiresPermissions("edu:course:eduVideoHistory:view")
	@RequestMapping(value = {"list", ""})
	public String list(EduVideoHistory eduVideoHistory, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<EduVideoHistory> page = eduVideoHistoryService.findPage(new Page<EduVideoHistory>(request, response), eduVideoHistory); 
		model.addAttribute("page", page);
		return "modules/edu/course/eduVideoHistoryList";
	}

	@RequiresPermissions("edu:course:eduVideoHistory:view")
	@RequestMapping(value = "form")
	public String form(EduVideoHistory eduVideoHistory, Model model) {
		model.addAttribute("eduVideoHistory", eduVideoHistory);
		return "modules/edu/course/eduVideoHistoryForm";
	}

	@RequiresPermissions("edu:course:eduVideoHistory:edit")
	@RequestMapping(value = "save")
	public String save(EduVideoHistory eduVideoHistory, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, eduVideoHistory)){
			return form(eduVideoHistory, model);
		}
		eduVideoHistoryService.save(eduVideoHistory);
		addMessage(redirectAttributes, "保存视频历史成功");
		return "redirect:"+Global.getAdminPath()+"/edu/course/eduVideoHistory/?repage";
	}
	
	@RequiresPermissions("edu:course:eduVideoHistory:edit")
	@RequestMapping(value = "delete")
	public String delete(EduVideoHistory eduVideoHistory, RedirectAttributes redirectAttributes) {
		eduVideoHistoryService.delete(eduVideoHistory);
		addMessage(redirectAttributes, "删除视频历史成功");
		return "redirect:"+Global.getAdminPath()+"/edu/course/eduVideoHistory/?repage";
	}

}